package chenji.dailykit.commandlisteners;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import chenji.dailykit.Main;
import chenji.dailykit.kit.SimpleKit;
/**
 * @author ChenJi Copyright (c) 2016 ChenJi. All rights reserved.
 */
public class CommandDKAdmin implements CommandExecutor {

	@Override
	public boolean onCommand(CommandSender arg0, Command arg1, String arg2, String[] arg3) {
		int length = arg3.length;
		if (length == 0) {
			if (arg0.hasPermission("DailyKit.admin.help")) {
				arg0.sendMessage("§c--------------------§aDailyKit §bAdmin§c--------------------");
				arg0.sendMessage("§c/DKAdmin [page] §a-列出所有的礼包和其类型。");
				arg0.sendMessage("§c/DKAdmin [type] §a-列出对应类型的所有礼包。");
				arg0.sendMessage("§c/DKAdmin send [name] [player] §a-给予一个玩家一个礼包。");
				arg0.sendMessage("§c/DKAdmin version §a-查看当前插件的版本。");
				arg0.sendMessage("§c/DKAdmin autocheckversion [true/false] §a-设置是否自动检测更新。");
				arg0.sendMessage("§c/DKAdmin checkverison §a-检查更新");
				if (arg0 instanceof Player) {
					arg0.sendMessage("§c/DKAdmin showall §a-打开一个界面展示所有礼包。");
					arg0.sendMessage("§c/DKAdmin get [name] §a-获取一个礼包。");
					arg0.sendMessage("§c/DKAdmin editor §a-打开礼包编辑器。");
					arg0.sendMessage("§c/DKAdmin editor [name] §a-打开一个礼包的礼包编辑器。");

				}
				arg0.sendMessage("§c-------------------------------------------------------");
			} else {
				arg0.sendMessage("§c你没有权限这样做。- DailyKit.admin.help");
			}

		}
		
		if (length != 0) {
			if (arg3[0].equalsIgnoreCase("get")) {
				if (arg0.hasPermission("DailyKit.admin.get")) {
					Player p = null;
					if (arg0 instanceof Player) {
						p = (Player) arg0;
					} else {
						arg0.sendMessage("§c对不起，控制台不能使用这个指令。");
					}
					if (length != 2) {
						arg0.sendMessage("§c正确用法：/DKAdmin get [name] §a-获取一个礼包。");
						return true;
					}
					String s = arg3[1];
					SimpleKit k = Main.getKitCenter().getSimpleKit(s);
					if (k == null) {
						arg0.sendMessage("§c对不起，你输入的礼包名是一个无效的礼包名。");
						return true;
					} else {
						p.getInventory().addItem(k.getShowItem());
						arg0.sendMessage("§c给予成功。");
					}
				} else {
					arg0.sendMessage("§c你没有权限这样做。- DailyKit.admin.get");
				}
			}
		}

		return true;
	}

}
